package edu.wpi.first.wpilibj.templates;

import java.io.PrintStream;

/**
 *
 * @author Robotics
 */
public class Debugger {
    public static final byte MAX_DEBUG_LEVELS = 16;
    
    private PrintStream ps;
    private boolean enabled;
    private boolean[] level;
    private String[] levelStrings;


    public Debugger() {
        this(System.out);
    }

    public Debugger(PrintStream p) {
        this(p, false);
    }
    
    public Debugger(boolean enable) {
        this(System.out, enable);
    }

    public Debugger(PrintStream p, boolean enable) {
        this(p, enable, new boolean[MAX_DEBUG_LEVELS],
                                                  new String[MAX_DEBUG_LEVELS]);
    }

    public Debugger(boolean enable, boolean[] levels) {
        ps = System.out;
        this.enabled = enable;
        level = levels;
    }

    public Debugger(boolean enable, boolean[] levels, String[] lStr) {
        this(System.out, enable, levels, lStr);
    }

    public Debugger(PrintStream p, boolean enable, boolean[] levels,
                                                                String[] lStr) {
        ps = p;
        this.enabled = enable;
        level = levels;
        levelStrings = lStr;
    }

    public void set(boolean[] levels) {
        this.level = levels;
    }

    public void enable() {
        enabled = true;
    }

    public void disable() {
        enabled = false;
    }

    /**
     * Print debug message to specified output stream
     * @param lev Debug "level" (1-based)
     * @param s Debug string
     */
    public void dbg(int lev, String msg) {
        if(enabled && level[lev - 1]) {
            dbg("[" + levelStrings[lev - 1] + "(" + lev + ")]" +
                                                               ": " + msg + ". ");
        }
    }
    
    public void dbg(String msg) {
        if(enabled) { ps.println(msg); }
    }


}
